package cst.a903dss.zyfypt_903dss.fragment;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;
import java.util.List;

import cst.a903dss.zyfypt_903dss.AmicoolListener;
import cst.a903dss.zyfypt_903dss.adapter.ProjectAdapter;
import cst.a903dss.zyfypt_903dss.Bean.ProjectBean;
import cst.a903dss.zyfypt_903dss.R;
import cst.a903dss.zyfypt_903dss.ResModel;

/**
 * Created by 双 on 2017/6/4.
 */

public class Fragment42 extends Fragment {
    private RecyclerView recyclerView;
    private ProjectAdapter adapter;
    private List<ProjectBean> list;
    private RecyclerView.LayoutManager layoutManager;
    private AmicoolListener<List<ProjectBean>> listener;
    private ResModel model;
    private SharedPreferences sp;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        View view=inflater.inflate(R.layout.fragment_42,container,false);
        recyclerView=(RecyclerView)view.findViewById(R.id.project_rec);
        adapter=new ProjectAdapter(getActivity());
        list=new ArrayList<ProjectBean>();
        layoutManager=new LinearLayoutManager(getActivity());
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setAdapter(adapter);
        listener=new AmicoolListener<List<ProjectBean>>() {
            @Override
            public void onResponse(List<ProjectBean> l) {
                adapter.setList(l);
            }

            @Override
            public void onFail(String msg) {

            }
        };
        sp=getActivity().getSharedPreferences("ME", Context.MODE_PRIVATE);
        model=new ResModel("gson",sp.getString("session_id",""));
        model.getList("project",1,listener);
        return view;
    }
}
